package com.ruoyi.activity.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.activity.req.WorksListReq;

import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.Works;
import com.ruoyi.activity.service.IWorksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品管理
 *
 * @author ruoyi
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/admin/works")
public class WorksController extends BaseController
{
    @Autowired
    private IWorksService worksService;

    /**
     * 查询作品管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WorksListReq works)
    {
        startPage();
        List<Works> list = worksService.selectWorksList(works);
        return getDataTable(list);
    }

    /**
     * 导出作品管理列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Works works)
    {
        WorksListReq worksListReq = new WorksListReq();
        //复制works属性到worksListReq
        BeanUtils.copyProperties(works, worksListReq);
        List<Works> list = worksService.selectWorksList(worksListReq);
        ExcelUtil<Works> util = new ExcelUtil<Works>(Works.class);
        util.exportExcel(response, list, "作品管理数据");
    }

    /**
     * 获取作品管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(worksService.selectWorksById(id));
    }

    /**
     * 新增作品管理
     */
    @PostMapping
    public AjaxResult add(@RequestBody Works works)
    {
        return toAjax(worksService.insertWorks(works));
    }

    /**
     * 修改作品管理
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Works works)
    {
        return toAjax(worksService.updateWorks(works));
    }

    /**
     * 删除作品管理
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(worksService.deleteWorksByIds(ids));
    }
}
